package com.droidclaimcustomer.helper.utils;

import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.droidclaimcustomer.helper.asyntask.ICompleteListener;
import com.droidclaimcustomer.helper.asyntask.IProgressTracker;
import com.droidclaimcustomer.helper.asyntask.ProgressAsynTask;
import com.droidclaimcustomer.helper.asyntask.SpinnerTracker;

public class DownloadImage extends ProgressAsynTask<String, Bitmap> {
	
	public DownloadImage(ICompleteListener listener){
		setTaskCompletionListener(listener);
		IProgressTracker tracker = new SpinnerTracker((Context)listener, "Download Image");
		setProgressTracker(tracker);
	}
	
	public String load(String url){
		String downloadImageTask = "DownloadImage";
		setTaskId(downloadImageTask);
		execute(url);
		return downloadImageTask;
	}

	@Override
	protected Bitmap performTaskInBackground(String... urls) throws Exception {
		Bitmap result = null;
		
		String urldisplay = urls[0];
		InputStream in = new java.net.URL(urldisplay).openStream();
		result = BitmapFactory.decodeStream(in);

		return result;
	}

}